﻿#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

using PdfCreative.Pdf.Writer.Embedding.Predictors;
using PdfCreative.Pdf.Writer.Utilities;

namespace PdfCreative.Pdf.Writer.Embedding
{
    /// <summary>
    /// The Predictor class is the base class for deflation predictor functions. The Predictor class is
    /// abstract. All predictor classes inheritor from the Predictor base class.
    /// </summary>
    internal abstract class Predictor
    {
        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Retrieves the padding in data that is encoded using the current predictor.
        /// </summary>
        public abstract int Padding { get; }
        #endregion



        // Public methods
        // ==============
        #region Public methods
        /// <summary>
        /// Decodes a line in the specified buffer.
        /// </summary>
        /// <param name="buffer">The buffer</param>
        /// <param name="offset">The offset at which to decode.</param>
        /// <param name="width">The width of the matrix that the buffer represents.</param>
        public abstract void Decode(byte[] buffer, int offset, int width);

        /// <summary>
        /// Retrieves a predictor that matches the specified code.
        /// If no predictor was found for the code, this method returns a Null reference.
        /// </summary>
        /// <param name="predictorCode">The predictor code</param>
        /// <returns>The predictor.</returns>
        public static Predictor GetPredictor(PredictorCode predictorCode)
        {
            return
                ReflectionUtilities.GetMatchingInstance<Predictor, PredictorAttribute>(
                delegate(PredictorAttribute attr) { return attr.PredictorCode == predictorCode; });

        } // GetPredictor()
        #endregion
    }
}
